{% extends site.theme|stringformat:"s/include/commbase.html" %}
{% block title %}留言簿 - {% endblock %}
{% block commain %}
<div id="addmessage"><form id="addmsgForm">
<div class="tableTitle"><span>添加留言信息</span></div>
	<table class="commTable" style="margin:2px 0px 10px 0px;">
		<tr><td class="tableLabel">{{gbookForm.authorname.label}}（必填）：</td><td style="width: 180px;">{{gbookForm.authorname}}</td>
			<td rowspan="3" class="gbookmessage">{{gbookForm.title}}<br/>{{gbookForm.message}}</td></tr>
		<tr><td class="tableLabel">{{gbookForm.email.label}}（必填）：</td><td>{{gbookForm.email}}</td></tr>
		{% include site.theme|stringformat:"s/include/safecode.html" with safecode=loginForm.safecode etype='article' %}
		<tr><td colspan="3" style="padding-left: 20px; text-align:center;"><input type="button" value="提交" OnClick="addMsg();"><input id="btmReset" type="reset" value="重置"><input name="_retType"  id="_retType" type="Hidden" value="json"><input name="pid"  id="id_pid" type="Hidden" value="-1"></td></tr>
	</table></form>
	<script type="text/javascript">
	<!--
	var myTitle = '填写{{gbookForm.title.label}}......';
	var myMessage = '填写{{gbookForm.message.label}}......';
	initMsg();
	function initMsg(){
		$('#id_message').val(myMessage);
		$('#id_message').bind({
			focusin: function(){if($('#id_message').val()==myMessage){$('#id_message').val('');}},
			focusout: function(){if($('#id_message').val()==''){$('#id_message').val(myMessage);}}
		});
		
		$('#id_title').val(myTitle);
		$('#id_title').bind({
			focusin: function(){if($('#id_title').val()==myTitle){$('#id_title').val('');}},
			focusout: function(){if($('#id_title').val()==''){$('#id_title').val(myTitle);}}
		});
	}
	function addMsg(){
		$.dialog.confirm('确定要发布此留言么?',
			function(){
				if($('#id_message').val()==myMessage){$('#id_content').val('');}
				if($('#id_title').val()==myTitle){$('#id_title').val('');}
				$('#msgList').prepend("<div id='loading'>Loading......</div>");
				var url="/addGBook.do";
				$.post(url, $('#addmsgForm').serialize(),function (data){
					if(data.flag){$.dialog.alert(data.msg, function(){
						$('#msgList').prepend(data.html);$('#loading').remove();$('#btmReset').click();reloadSCimage();});
					}else {$.dialog.alert(data.msg);$('#loading').remove();}
					if($('#id_message').val()==''){$('#id_message').val(myMessage);}
				},'json');
			},
			function(){}
		);
	}
	function showreply(id){
		$('#replyFormDiv #_id').attr('value',id);
		$('#e-'+id+' .gbookMsg').append($('#replyForm'));
		if($('#e-'+id+'-reply')){$('#id_reply').attr('value', $('#e-'+id+'-reply').text());$('#e-'+id+'-reply').hide();}
	}
	function replyMsg(){
		if($('#id_reply').val()==''){$.dialog.alert('回复内容不能不为空！');}
		else{$.dialog.confirm('确定要发布此回复么?',
				function(){
					var url="/replyGBook.do";
					$.post(url, $('#replyForm').serialize(), function (data){
						if(data.flag){$.dialog.alert(data.msg, function(){id=$('#replyForm #_id').value;
							$('#e-'+id+'-reply').remove();$('#replyForm').before(data.html); $('#replyForm').val(''); $('#replyFormDiv').append($('#replyForm'));
							});
						}else {$.dialog.alert(data.msg);}
					},'json');
				},
				function(){}
			);
		}
	}
	//-->
	</script>
</div>
<div id="replyFormDiv" style="display:none;"><form id="replyForm"><div class="msgReply">{{gbookForm.reply}}<input name="_id"  id="_id" type="Hidden" value="-1"><input name="_retType"  id="_retType" type="Hidden" value="json"><br />
			<input id="btnOK" type="button" value="提交" onClick="replyMsg();"><input id="btnCancel" type="button"" value="取消" onClick="$('#replyFormDiv').append($('#replyForm'));$('.msgReply').show();"></div></div></form></div>
<div class="tableTitle"><span>留言信息({{listGBooks|length}})</span></div>
<div id="msgList">
	{% for e in listGBooks %}<div id="e-{{e.id}}" class="guestbook">
		<div class="msgIcon"><img alt="{{e.authorname}}" src="/static/{{site.theme}}/images/avatar.gif"> <br/>{{ e.authorname }}</div>
		<div class=gbookMsg>
		   	<div class="msgTitle"><span style="float: left; white-space:nowrap; "> {{e.title|default:''}}</span>
		   		<span style="float:right; font-weight: normal; text-align: right; line-height:20px; margin-top:-3px;">发表于: {{ e.crtdate|date:"Y-m-d H:i:s" }}{% if site.power.user.power >= 100 %}&nbsp;&nbsp;&nbsp;<a href="javascript:deleteByID('/deleteGBook-{{e.id}}.do', 'e-{{e.id}}');">删除</a>&nbsp;&nbsp;&nbsp;<a href="javascript:showreply({{e.id}});">回复</a>{% endif %}</span>
		   	</div>
		   	<div class="msgContent">{{ e.message|default:'' }}</div>
		   	{% if e.reply %}<div id="e-{{e.id}}-reply" class="msgReply">{{ e.reply|default:'' }}</div>{% endif %}
		</div>
	</div>{% empty %}暂时没有评论！{% endfor %}
</div>
{% include site.theme|stringformat:"s/include/pager.html" with pager=pager %}
{% endblock %}